home *** CD-ROM | disk | FTP | other *** search
/ SGI Varsity Update 1998 August / SGI Varsity Update 1998 August.iso / dist / patchSG0002824.idb / usr / include / sys / socket.h.z / socket.h
C/C++ Source or Header  |  1998-07-29  |  14KB  |  421 lines

  1. /*
  2.  * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  *
  33.  */
  34.  
  35. #ifndef __SYS_TPI_SOCKET_H__
  36. #ifndef _SYS_SOCKET_H_
  37. #define    _SYS_SOCKET_H_
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41.  
  42. #include <sys/bsd_types.h>
  43.  
  44. /*
  45.  * Definitions related to sockets: types, address families, options.
  46.  */
  47.  
  48. /*
  49.  * Types
  50.  */
  51.  
  52. #ifndef NC_TPI_CLTS
  53. #define NC_TPI_CLTS    1        /* must agree with netconfig.h */
  54. #define NC_TPI_COTS    2        /* must agree with netconfig.h */
  55. #define NC_TPI_COTS_ORD    3        /* must agree with netconfig.h */
  56. #define    NC_TPI_RAW    4        /* must agree with netconfig.h */
  57. #endif /* !NC_TPI_CLTS */
  58.  
  59. #define    SOCK_DGRAM    NC_TPI_CLTS    /* datagram socket */
  60. #define    SOCK_STREAM    NC_TPI_COTS    /* stream socket */
  61. #define    SOCK_RAW    NC_TPI_RAW    /* raw-protocol interface */
  62. #define    SOCK_RDM    5        /* reliably-delivered message */
  63. #define    SOCK_SEQPACKET    6        /* sequenced packet stream */
  64.  
  65. /*
  66.  * Option flags per-socket.
  67.  */
  68. #define    SO_DEBUG    0x0001        /* turn on debugging info recording */
  69. #define    SO_ACCEPTCONN    0x0002        /* socket has had listen() */
  70. #define    SO_REUSEADDR    0x0004        /* allow local address reuse */
  71. #define    SO_KEEPALIVE    0x0008        /* keep connections alive */
  72. #define    SO_DONTROUTE    0x0010        /* just use interface addresses */
  73. #define    SO_BROADCAST    0x0020        /* permit sending of broadcast msgs */
  74. #define    SO_USELOOPBACK    0x0040        /* bypass hardware when possible */
  75. #define    SO_LINGER    0x0080        /* linger on close if data present */
  76. #define    SO_OOBINLINE    0x0100        /* leave received OOB data in line */
  77. #define    SO_REUSEPORT    0x0200        /* allow local address,port reuse */
  78. #define SO_ORDREL    0x0200        /* MIPS ABI - unimplemented */
  79. #define SO_IMASOCKET    0x0400        /* use libsocket (not TLI) semantics */
  80. #define    SO_CHAMELEON    0x1000        /* (cipso) set label to 1st req rcvd */
  81. #define SO_PASSIFNAME    0x2000        /* Pass the Ifname in front of data */
  82.  
  83. /*
  84.  * Additional options, not kept in so_options.
  85.  */
  86. #define SO_SNDBUF    0x1001        /* send buffer size */
  87. #define SO_RCVBUF    0x1002        /* receive buffer size */
  88. #define SO_SNDLOWAT    0x1003        /* send low-water mark */
  89. #define SO_RCVLOWAT    0x1004        /* receive low-water mark */
  90. #define SO_SNDTIMEO    0x1005        /* send timeout */
  91. #define SO_RCVTIMEO    0x1006        /* receive timeout */
  92. #define    SO_ERROR    0x1007        /* get error status and clear */
  93. #define    SO_TYPE        0x1008        /* get socket type */
  94. #define SO_PROTOTYPE    0x1009        /* get protocol type (libsocket) */
  95.  
  96. /*
  97.  * Structure used for manipulating linger option.
  98.  */
  99. struct    linger {
  100.     int    l_onoff;        /* option on/off */
  101.     int    l_linger;        /* linger time */
  102. };
  103.  
  104. /*
  105.  * Level number for (get/set)sockopt() to apply to socket itself.
  106.  */
  107. #define    SOL_SOCKET    0xffff        /* options for socket level */
  108.  
  109. /*
  110.  * Address families.
  111.  */
  112. #define    AF_UNSPEC    0        /* unspecified */
  113. #define    AF_LOCAL    1        /* local to host (pipes, portals) */
  114. #define    AF_UNIX        AF_LOCAL    /* backward compatibility */
  115. #define    AF_INET        2        /* internetwork: UDP, TCP, etc. */
  116. #define    AF_IMPLINK    3        /* arpanet imp addresses */
  117. #define    AF_PUP        4        /* pup protocols: e.g. BSP */
  118. #define    AF_CHAOS    5        /* mit CHAOS protocols */
  119. #define    AF_NS        6        /* XEROX NS protocols */
  120. #define    AF_ISO        7        /* ISO protocols */
  121. #define    AF_ECMA        8        /* european computer manufacturers */
  122. #define    AF_DATAKIT    9        /* datakit protocols */
  123. #define    AF_CCITT    10        /* CCITT protocols, X.25 etc */
  124. #define    AF_SNA        11        /* IBM SNA */
  125. #define AF_DECnet    12        /* DECnet */
  126. #define AF_DLI        13        /* DEC Direct data link interface */
  127. #define AF_LAT        14        /* LAT */
  128. #define    AF_HYLINK    15        /* NSC Hyperchannel */
  129. #define    AF_APPLETALK    16        /* Apple Talk */
  130. #define    AF_ROUTE    17        /* Internal Routing Protocol */
  131. #ifdef __sgi
  132. #define    AF_RAW        18        /* Raw link layer interface */
  133. #else
  134. #define    AF_LINK        18        /* Link layer interface */
  135. #endif
  136. #define    pseudo_AF_XTP    19        /* eXpress Transfer Protocol (no AF) */
  137.  
  138. /* MIPS ABI VALUES - unimplemented - notice these overlap real values */
  139. #define AF_NIT        17        /* Network Interface Tap */
  140. #define AF_802        18        /* IEEE 802.2, also ISO 8802 */
  141. #define AF_OSI        19        /* umbrella for all families used */
  142. #define AF_X25        20        /* CCITT X.25 in particular */
  143. #define AF_OSINET    21        /* AFI = 47, IDI = 4 */
  144. #define AF_GOSIP    22        /* U.S. Government OSI */
  145.  
  146. #define AF_SDL        23        /* SGI Data Link for DLPI */
  147. #define AF_INET6    24        /* Internet Protocol version 6 */
  148. #define    AF_LINK        25        /* Link layer interface */
  149.  
  150. #define AF_MAX        (AF_LINK+1)
  151.  
  152. /*
  153.  * Structure used by kernel to store most
  154.  * addresses.
  155.  * NOTE: For Raganarok compilers we MUST have a union for sockaddr which
  156.  * specifies integer data, otherwise the compiler will only enforce
  157.  * half-word alignment and modules using alternate defines (sockaddr_in)
  158.  * will get Address Error exceptions on word accesses.
  159.  */
  160. struct sockaddr {
  161.   union {
  162.     struct {
  163. #undef _HAVE_SA_LEN            /* marker for some places to change */
  164. #ifdef _HAVE_SA_LEN            /* when we have sin_len */
  165.     u_char    sa_len2;        /* total length */
  166.     u_char    sa_family2;        /* address family */
  167. #else
  168.     u_short    sa_family2;        /* address family */
  169. #endif
  170.     char    sa_data2[14];        /* up to 14 bytes of direct address */
  171.       } sa_generic;
  172.     int sa_align;
  173.   } sa_union;
  174. };
  175. #define sa_len        sa_union.sa_generic.sa_len2
  176. #define sa_family    sa_union.sa_generic.sa_family2
  177. #define    sa_data        sa_union.sa_generic.sa_data2
  178. #ifndef _HAVE_SIN_LEN
  179. struct sockaddr_new {
  180.   union {
  181.     struct {
  182.     u_char    sa_len2;        /* total length */
  183.     u_char    sa_family2;        /* address family */
  184.     char    sa_data2[14];        /* up to 14 bytes of direct address */
  185.       } sa_generic;
  186.     int sa_align;
  187.   } sa_union;
  188. };
  189. #define _SIN_ADDR_SIZE        8        /* size of sockaddr_in data */
  190. #define _SIN_SA_DATA_SIZE    14        /* size of sa_data array */
  191.  
  192. #define _MAX_SA_LEN    20        /* largest sockaddr for now (_dl) */
  193. /* Fake .sa_len for sources or destinations.
  194.  */
  195. #define _FAKE_SA_LEN_SRC(sa) (((struct sockaddr_new*)(sa))->sa_len    \
  196.                   ? ((struct sockaddr_new*)(sa))->sa_len    \
  197.                   : ((sa)->sa_family == AF_INET ? _SIN_ADDR_SIZE \
  198.                  : ((sa)->sa_family == AF_LINK ? _MAX_SA_LEN \
  199.                     : sizeof(struct sockaddr))))
  200. #define _FAKE_SA_LEN_DST(sa) (((struct sockaddr_new*)(sa))->sa_len    \
  201.                   ? ((struct sockaddr_new*)(sa))->sa_len    \
  202.                   : ((sa)->sa_family == AF_LINK ? _MAX_SA_LEN \
  203.                  : sizeof(struct sockaddr)))
  204. #endif
  205.  
  206. #if defined (_KERNEL) /* Trusted IRIX */
  207. struct mac_label;
  208.  
  209. /*
  210.  * CIPSO: structure passed in MT_SONAME mbuf from sbappendaddr() to recvit()
  211.  */
  212. struct sockaddrlbl {
  213.     struct sockaddr  sal_addr;    /* datagram source address */
  214.     struct mac_label *sal_lbl;    /* label of datagram */
  215.     uid_t sal_uid;            /* uid of datagram */
  216. };
  217. #endif
  218.  
  219. struct recvluinfo {                     /* argument to recvlumsg */
  220.     struct mac_label *rlu_label;
  221.     uid_t         *rlu_uidp;
  222. };
  223.  
  224. /*
  225.  * Structure used by kernel to pass protocol
  226.  * information in raw sockets.
  227.  */
  228. struct sockproto {
  229.     u_short    sp_family;        /* address family */
  230.     u_short    sp_protocol;        /* protocol */
  231. };
  232.  
  233. /*
  234.  * An option specification consists of an opthdr, followed by the value of
  235.  * the option.  An options buffer contains one or more options.  The len
  236.  * field of opthdr specifies the length of the option value in bytes.  This
  237.  * length must be a multiple of sizeof(int) (use OPTLEN macro).
  238.  */
  239.  
  240. struct opthdr {
  241.     int            level;  /* protocol level affected */
  242.     int            name;   /* option to modify */
  243.     int            len;    /* length of option value */
  244. };
  245.  
  246. #define OPTLEN(x) ((((x) + sizeof(int) - 1) / sizeof(int)) * sizeof(int))
  247. #define OPTVAL(opt) ((char *)(opt + 1))
  248.  
  249. /*
  250.  * the optdefault structure is used for internal tables of option default
  251.  * values.
  252.  */
  253. struct optdefault {
  254.     int    optname;    /* the option */
  255.     char    *val;        /* ptr to default value */
  256.     int    len;        /* length of value */
  257. };
  258.  
  259. struct tpisocket;
  260. struct T_optmgmt_req;
  261. struct msgb;
  262.  
  263. /*
  264.  * the opproc structure is used to build tables of options processing
  265.  * functions for dooptions().
  266.  */
  267. struct opproc {
  268.     int    level;        /* options level this function handles */
  269.     int    (*func)(struct tpisocket *, struct T_optmgmt_req *,
  270.             struct opthdr *, struct msgb *);
  271.                 /* the function */
  272. };
  273.  
  274. /*
  275.  * This structure is used to encode pseudo system calls
  276.  */
  277. struct socksysreq {
  278.     int             args[7];
  279. };
  280.  
  281. /*
  282.  * This structure is used for adding new protocols to the list supported by
  283.  * sockets.
  284.  */
  285.  
  286. struct socknewproto {
  287.     int             family;    /* address family (AF_INET, etc.) */
  288.     int             type;    /* protocol type (SOCK_STREAM, etc.) */
  289.     int             proto;    /* per family proto number */
  290.     dev_t           dev;    /* major/minor to use (must be a clone) */
  291.     int             flags;    /* protosw flags */
  292. };
  293.  
  294. /*
  295.  * Protocol families, same as address families for now.
  296.  */
  297. #define    PF_UNSPEC    AF_UNSPEC
  298. #define    PF_LOCAL    AF_LOCAL
  299. #define    PF_UNIX        PF_LOCAL    /* backward compatibility */
  300. #define    PF_INET        AF_INET
  301. #define    PF_IMPLINK    AF_IMPLINK
  302. #define    PF_PUP        AF_PUP
  303. #define    PF_CHAOS    AF_CHAOS
  304. #define    PF_NS        AF_NS
  305. #define    PF_ISO        AF_ISO
  306. #define    PF_OSI        AF_ISO
  307. #define    PF_ECMA        AF_ECMA
  308. #define    PF_DATAKIT    AF_DATAKIT
  309. #define    PF_CCITT    AF_CCITT
  310. #define    PF_SNA        AF_SNA
  311. #define PF_DECnet    AF_DECnet
  312. #define PF_DLI        AF_DLI
  313. #define PF_LAT        AF_LAT
  314. #define    PF_HYLINK    AF_HYLINK
  315. #define    PF_APPLETALK    AF_APPLETALK
  316. #define    PF_ROUTE    AF_ROUTE
  317. #define    PF_LINK        AF_LINK
  318. #define    PF_XTP        pseudo_AF_XTP    /* really just proto family, no AF */
  319. #define    PF_RAW        AF_RAW
  320.  
  321. /* MIPS ABI VALUES - unimplemented */
  322. #define PF_NIT        AF_NIT        /* Network Interface Tap */
  323. #define PF_802        AF_802        /* IEEE 802.2, also ISO 8802 */
  324. #define PF_X25        AF_X25        /* CCITT X.25 in particular */
  325. #define PF_OSINET    AF_OSINET    /* AFI = 47, IDI = 4 */
  326. #define PF_GOSIP    AF_GOSIP    /* U.S. Government OSI */
  327. #define    PF_INET6    AF_INET6
  328.  
  329. #define    PF_MAX        AF_MAX
  330.  
  331. /*
  332.  * Definitions for network related sysctl, CTL_NET.
  333.  *
  334.  * Second level is protocol family.
  335.  * Third level is protocol number.
  336.  */
  337.  
  338. /*
  339.  * PF_ROUTE - Routing table
  340.  *
  341.  * Three additional levels are defined:
  342.  *    Fourth: address family, 0 is wildcard
  343.  *    Fifth: type of info, defined below
  344.  *    Sixth: flag(s) to mask with for NET_RT_FLAGS
  345.  */
  346. #define NET_RT_DUMP    1        /* dump; may limit to a.f. */
  347. #define NET_RT_FLAGS    2        /* by flags, e.g. RESOLVING */
  348. #define NET_RT_IFLIST    3        /* survey interface list */
  349.  
  350. /*
  351.  * Fourth level sysctl() variables for IPPROTO_IP
  352.  */
  353. #define    IPCTL_FORWARDING    1    /* act as router */
  354. #define    IPCTL_SENDREDIRECTS    2    /* may send redirects when forwarding */
  355.  
  356. /*
  357.  * Fourth level sysctl() variables for IPPROTO_UDP
  358.  */
  359. #define    UDPCTL_CHECKSUM        1    /* checksum UDP packets */
  360.  
  361.  
  362. /*
  363.  * Maximum queue length specifiable by listen.
  364.  * Applications can always reduce this in the listen call.
  365.  */
  366. #define    SOMAXCONN    1000
  367.  
  368. /*
  369.  * Message header for recvmsg and sendmsg calls.
  370.  * Used value-result for recvmsg, value only for sendmsg.
  371.  */
  372. struct msghdr {
  373.     caddr_t    msg_name;        /* optional address */
  374.     int    msg_namelen;        /* size of address */
  375.     struct    iovec *msg_iov;        /* scatter/gather array */
  376.     int    msg_iovlen;        /* # elements in msg_iov */
  377.     caddr_t    msg_accrights;        /* access rights sent/received */
  378.     int    msg_accrightslen;
  379. };
  380.  
  381. #define    MSG_OOB        0x1        /* process out-of-band data */
  382. #define    MSG_PEEK    0x2        /* peek at incoming message */
  383. #define    MSG_DONTROUTE    0x4        /* send without using routing tables */
  384. #define    MSG_EOR        0x8        /* data completes record */
  385. #define    MSG_TRUNC    0x10        /* data discarded before delivery */
  386. #define    MSG_CTRUNC    0x20        /* control data lost before delivery */
  387. #define    MSG_WAITALL    0x40        /* wait for full request or error */
  388. #define    MSG_DONTWAIT    0x80        /* this message should be nonblocking */
  389. #ifdef XTP
  390. #define    MSG_BTAG    0x40        /* XTP packet with BTAG field */
  391. #define    MSG_ETAG    0x80        /* XTP packet with ETAG field */
  392. #endif
  393.  
  394. #define    MSG_MAXIOVLEN    16
  395.  
  396. #if !defined(_KERNEL)
  397. extern int accept(int, void *, int *);
  398. extern int bind(int, const void *, int);
  399. extern int connect(int, const void *, int);
  400. extern int getpeername(int, void *, int *);
  401. extern int getsockname(int, void *, int *);
  402. extern int getsockopt(int, int, int, void *, int *);
  403. extern int setsockopt(int, int, int, const void *, int);
  404. extern int listen(int, int);
  405. extern int recv(int, void *, int, int);
  406. extern int recvfrom(int, void *, int, int, void *, int *);
  407. extern int recvmsg(int, struct msghdr *, int);
  408. extern int send(int, const void *, int, int);
  409. extern int sendto(int, const void *, int, int, const void *, int);
  410. extern int sendmsg(int, const struct msghdr *, int);
  411. extern int shutdown(int, int);
  412. extern int socket(int, int, int);
  413. extern int socketpair(int, int, int, int *);
  414. #endif
  415.  
  416. #ifdef __cplusplus
  417. }
  418. #endif
  419. #endif /* !__SYS_SOCKET_H__ */
  420. #endif /* !__SYS_TPI_SOCKET_H__ */
  421.